package com.sl.au.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.sl.au.entity.Account;
import com.sl.au.entity.EXDEviewPaymentTotal;
import com.sl.au.service.EXDEPayIncomeService;

/**
 * 销售收入统计控制器
 * @author yry
 * 2017-02-20
 */
@RestController
@RequestMapping(value="/ui/payIncome")//
public class PayIncomeController extends BaseController{
	
	@Autowired
	EXDEPayIncomeService exdePayIncomeService;
	
    @RequestMapping(method = RequestMethod.GET)
    public ModelAndView index(){
        ModelAndView modelAndView=createLayoutView("paymentSearch/payIncome");
        Account a = this.getMyAccount();
		String userId =a.getUser().getId();
		modelAndView.addObject("userId",userId);
		return modelAndView;
    }
    /**
     * 获取每年12个月的数据
     * @param request
     * @return
     */
    @RequestMapping(value = "/getMyTrance", method = RequestMethod.GET)
	public Map<String,Object> getMyTrance(HttpServletRequest request) {
		Map<String,Object> map = new HashMap<String,Object>();
		Map<String,String> condition = new HashMap<String,String>();
		Account a = this.getMyAccount();
		//String userId = a.getUser().getId();
		String year = request.getParameter("year");//年份

		List<EXDEviewPaymentTotal> users = null;
        //condition.put("userId", userId);
        condition.put("year", year);
		users = exdePayIncomeService.getMyPage(condition);
        long count = users.size();
		
		map.put("data", users);
		map.put("draw", request.getParameter("draw"));
		map.put("recordsFiltered", count);
		map.put("recordsTotal", count);
		return map;
	}
}
